package grgu.rud.glava9.c5;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;

public abstract class StudentWriteFactory {

	public static void studentsToFile(LinkedList<Student> studentList, File file)
			throws IOException {
		BufferedWriter bWriter = new BufferedWriter(new FileWriter(file));
		Iterator<Student> iterator = studentList.iterator();

		while (iterator.hasNext()) {
			Student s = iterator.next();
			System.out.println(s.getSurname() + " " + s.getAverageMark());
			s.makeSomeSurnameUp();
			String tempMarks = "";

			for (int i = 0; i < s.getMarks().length; i++) {
				tempMarks += s.getMarks()[i] + " ";
			}

			bWriter.append(s.getSurname() + " " + tempMarks);
			bWriter.newLine();
			bWriter.flush();
		}
	}

}
